﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBMigrator.Core.DbObjects.Data.Select;
using DBMigrator.Core.DbObjects.Data.Where;
using Rhino.Mocks;
using Xunit;

namespace DBMigrator.Core.Tests.DbObjects.Data
{
    public class SelectCountTests
    {
        private readonly IFrom from;
        private readonly IWhere where;

        public SelectCountTests()
        {
            from = MockRepository.GenerateMock<IFrom>();
            where = MockRepository.GenerateMock<IWhere>();
        }

        [Fact]
        public void SqlGenerationTypeShouldReturnISelect()
        {
            Assert.Equal(typeof(ISelectCount), new SelectCount(from, where, "ColumnName").SqlGenerationType);
        }

        [Fact]
        public void ConstructorShouldThrowIfColumnNameIsNull()
        {
            Assert.Throws<ArgumentNullException>(() => new SelectCount(from, where, null));
        }

        [Fact]
        public void ConstructorShouldThrowIfColumnNameIsEmpty()
        {
            Assert.Throws<ArgumentNullException>(() => new SelectCount(from, where, string.Empty));
        }

        [Fact]
        public void ConstructorShouldSetColumnName()
        {
            var columnName = StringUtil.Random();
            Assert.Equal(columnName, new SelectCount(from, where, columnName).ColumnName);
        }
    }
}
